package com.eascs.p2p.admin.service.impl;

import java.util.List;

import javax.inject.Inject;

import com.alibaba.dubbo.config.annotation.Service;
import com.eascs.p2p.admin.manager.IAdminResourceManager;
import com.eascs.p2p.common.entity.AdminResourceEntity;
import com.eascs.p2p.common.entity.AdminRoleEntity;
import com.eascs.p2p.common.service.IAdminResourceService;
import com.eascs.p2p.common.vo.ModelResult;

@Service
public class AdminResourceServiceImpl implements IAdminResourceService {
	@Inject
	IAdminResourceManager adminResourceManager;

	
	@Override
	public ModelResult<List<AdminResourceEntity>> selectResourcesListByCode(String code) {
		ModelResult<List<AdminResourceEntity>> result = new ModelResult<List<AdminResourceEntity>>();
		try {
			result.setModel(adminResourceManager.selectResourcesListByCode(code));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError(" 根据Code查询资源权限：", e.getMessage());
		}
		return result;
	}

	
	@Override
	public ModelResult<String> insertResources(AdminResourceEntity sysResources) {
		ModelResult<String> result = new ModelResult<String>();
		try {
			result.setModel(adminResourceManager.insertResources(sysResources));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError(" 添加资源：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<Boolean> updateResources(AdminResourceEntity sysResources) {
		ModelResult<Boolean> result = new ModelResult<Boolean>();
		try {
			result.setModel(adminResourceManager.updateResources(sysResources));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError(" 修改资源：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<Integer> deleteResources(AdminResourceEntity sysResources) {
		ModelResult<Integer> result = new ModelResult<Integer>();
		try {
			result.setModel(adminResourceManager.deleteResources(sysResources));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError(" 删除资源：", e.getMessage());
		}
		return result;
	}

	
	
	
	

	@Override
	public ModelResult<List<AdminResourceEntity>> selectUnDefaultResourcesList() {
		ModelResult<List<AdminResourceEntity>> result = new ModelResult<List<AdminResourceEntity>>();
		try {
			result.setModel(adminResourceManager.selectUnDefaultResourcesList());
		} catch (Exception e) {
			e.printStackTrace();
			result.withError(" 查询不是默认资源权限列表：", e.getMessage());
		}
		return result;
	}

	
	
	@Override
	public ModelResult<List<AdminResourceEntity>> selectResourcesByRoles(List<AdminRoleEntity> roles) {
		ModelResult<List<AdminResourceEntity>> result = new ModelResult<List<AdminResourceEntity>>();
		try {
			result.setModel(adminResourceManager.selectResourcesByRoles(roles));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError(" 查询资源权限：", e.getMessage());
		}
		return result;
	}
	
	@Override
	public ModelResult<List<AdminResourceEntity>> selectDefaultResourcesList() {
		ModelResult<List<AdminResourceEntity>> result = new ModelResult<List<AdminResourceEntity>>();
		try {
			result.setModel(adminResourceManager.selectDefaultResourcesList());
		} catch (Exception e) {
			e.printStackTrace();
			result.withError(" 查询默认资源权限列表：", e.getMessage());
		}
		return result;
	}
	@Override
	public ModelResult<List<AdminResourceEntity>> selectResourcesList() {
		ModelResult<List<AdminResourceEntity>> result = new ModelResult<List<AdminResourceEntity>>();
		try {
			result.setModel(adminResourceManager.selectResourcesList());
		} catch (Exception e) {
			e.printStackTrace();
			result.withError(" 查询资源权限列表：", e.getMessage());
		}
		return result;
	}

	
	

}
